diff options
author | Oliver Wolff <oliver.wolff@nokia.com> | 2011-11-17 11:02:39 +0100 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@nokia.com> | 2011-11-17 11:07:27 +0100 |
commit | abb0ddc6179eb368a3af5a9bbaaa9bc9ff480d53 (patch) | |
tree | babc3a0bde897dec20f5773a6d1edfaeeb6f4829 | |
parent | d3b3f88435c939ea5f6abe0cf5d29a25fb4cbed9 (diff) |
Restrict touch events to actual display area
Reviewed-by: Rainer Keller
-rw-r--r-- | src/other/inputfilter.cpp | 10 | ||||
-rw-r--r-- | src/other/inputfilter.h | 1 | ||||
-rw-r--r-- | src/other/panmodefilter.cpp | 12 | ||||
-rw-r--r-- | src/other/pinchmodefilter.cpp | 18 | ||||
-rw-r--r-- | src/other/swipemodefilter.cpp | 17 | ||||
-rw-r--r-- | src/other/widget.h | 2 | ||||
-rw-r--r-- | src/other/widgetmanager.cpp | 2 |
7 files changed, 48 insertions, 14 deletions
diff --git a/src/other/inputfilter.cpp b/src/other/inputfilter.cpp index d98da52..d574ef8 100644 --- a/src/other/inputfilter.cpp +++ b/src/other/inputfilter.cpp @@ -118,3 +118,13 @@ void InputFilter::removeValuePoints() qDeleteAll(mValuePoints); mValuePoints.clear(); } + +QPointF InputFilter::constrainPointToRectangle(const QPointF &point, const QRectF &rectangle) +{ + QPointF returnValue = point; + returnValue.setX(qMax(returnValue.x(), (qreal)rectangle.x())); + returnValue.setX(qMin(returnValue.x(), (qreal)rectangle.width())); + returnValue.setY(qMax(returnValue.y(), (qreal)rectangle.y())); + returnValue.setY(qMin(returnValue.y(), (qreal)rectangle.height())); + return returnValue; +} diff --git a/src/other/inputfilter.h b/src/other/inputfilter.h index 77db5dc..2bab4ae 100644 --- a/src/other/inputfilter.h +++ b/src/other/inputfilter.h @@ -54,6 +54,7 @@ protected: QtSimulatorPrivate::TouchEventData createTouchEventFromMouseEvent(Widget *widget, QGraphicsSceneMouseEvent *mouseEvent); void removeValuePoints(); + QPointF constrainPointToRectangle(const QPointF &point, const QRectF &rectangle); }; #endif // INPUTFILTER_H diff --git a/src/other/panmodefilter.cpp b/src/other/panmodefilter.cpp index 868d047..0757159 100644 --- a/src/other/panmodefilter.cpp +++ b/src/other/panmodefilter.cpp @@ -34,6 +34,8 @@ #include "mouseindicator.h" #include "widget.h" #include "application.h" +#include "widgetmanager.h" +#include "displaywidget.h" #include <QtGui/QGraphicsSceneEvent> @@ -50,7 +52,9 @@ PanModeFilter::~PanModeFilter() bool PanModeFilter::sceneEventFilter(QGraphicsItem *watched, QEvent *event) { Widget *widget = static_cast<Widget *>(watched); + const QRectF displayRect = widget->widgetManager()->display()->boundingRect(); QGraphicsSceneMouseEvent *ev = 0; + QPointF validPoint; QtSimulatorPrivate::TouchEventData touchEvent; switch (event->type()) { case QEvent::GraphicsSceneMousePress: @@ -107,13 +111,15 @@ bool PanModeFilter::sceneEventFilter(QGraphicsItem *watched, QEvent *event) break; case QEvent::GraphicsSceneMouseMove: ev = static_cast<QGraphicsSceneMouseEvent *>(event); + validPoint = constrainPointToRectangle(ev->pos(), displayRect); switch (mState) { case updateFirstPoint: - mValuePoints[0]->setCenter(ev->pos()); + mValuePoints[0]->setCenter(validPoint); return true; case updateSecondPoint: - mValuePoints[1]->setCenter(ev->pos()); - mValuePoints[0]->setCenter(mValuePoints[1]->center() - mPanDiff); + mValuePoints[1]->setCenter(validPoint); + validPoint = constrainPointToRectangle(ev->pos() - mPanDiff, displayRect); + mValuePoints[0]->setCenter(validPoint); touchEvent = createTouchEventFromMouseEvent(widget, ev); QtSimulatorPrivate::RemoteMetacall<void>::call(widget->owner->socket(), QtSimulatorPrivate::NoSync, diff --git a/src/other/pinchmodefilter.cpp b/src/other/pinchmodefilter.cpp index 3690c3a..9a2f402 100644 --- a/src/other/pinchmodefilter.cpp +++ b/src/other/pinchmodefilter.cpp @@ -34,6 +34,8 @@ #include "mouseindicator.h" #include "widget.h" #include "application.h" +#include "widgetmanager.h" +#include "displaywidget.h" #include <QtGui/QGraphicsSceneEvent> @@ -53,7 +55,9 @@ PinchModeFilter::~PinchModeFilter() bool PinchModeFilter::sceneEventFilter(QGraphicsItem *watched, QEvent *event) { Widget *widget = static_cast<Widget *>(watched); + const QRectF displayRect = widget->widgetManager()->display()->boundingRect(); QGraphicsSceneMouseEvent *ev = 0; + QPointF validPoint; QtSimulatorPrivate::TouchEventData touchEvent; QPointF diff; switch (event->type()) { @@ -71,11 +75,13 @@ bool PinchModeFilter::sceneEventFilter(QGraphicsItem *watched, QEvent *event) mReferencePoint->setCursor(Qt::ClosedHandCursor); mState = updateReferencePoint; } else { - mValuePoints.append(new MouseIndicator(ev->pos(), widget)); + validPoint = constrainPointToRectangle(ev->pos(), displayRect); + mValuePoints.append(new MouseIndicator(validPoint, widget)); mValuePoints[0]->setStartPos(mValuePoints[0]->center()); mValuePoints[0]->setCursor(Qt::ClosedHandCursor); QPointF diff = ev->pos() - mReferencePoint->center(); - mValuePoints.append(new MouseIndicator(mReferencePoint->center() - diff, widget)); + validPoint = constrainPointToRectangle(mReferencePoint->center() - diff, displayRect); + mValuePoints.append(new MouseIndicator(validPoint, widget)); mValuePoints[1]->setStartPos(mValuePoints[1]->center()); mState = updateTouchPoints; touchEvent = createTouchEventFromMouseEvent(widget, ev); @@ -115,14 +121,16 @@ bool PinchModeFilter::sceneEventFilter(QGraphicsItem *watched, QEvent *event) break; case QEvent::GraphicsSceneMouseMove: ev = static_cast<QGraphicsSceneMouseEvent *>(event); + validPoint = constrainPointToRectangle(ev->pos(), displayRect); switch (mState) { case updateReferencePoint: - mReferencePoint->setCenter(ev->pos()); + mReferencePoint->setCenter(validPoint); return true; case updateTouchPoints: - mValuePoints[0]->setCenter(ev->pos()); + mValuePoints[0]->setCenter(validPoint); diff = ev->pos() - mReferencePoint->center(); - mValuePoints[1]->setCenter(mReferencePoint->center() - diff); + validPoint = constrainPointToRectangle(mReferencePoint->center() - diff, displayRect); + mValuePoints[1]->setCenter(validPoint); touchEvent = createTouchEventFromMouseEvent(widget, ev); QtSimulatorPrivate::RemoteMetacall<void>::call(widget->owner->socket(), QtSimulatorPrivate::NoSync, diff --git a/src/other/swipemodefilter.cpp b/src/other/swipemodefilter.cpp index 90de176..2ff9ef5 100644 --- a/src/other/swipemodefilter.cpp +++ b/src/other/swipemodefilter.cpp @@ -34,6 +34,8 @@ #include "mouseindicator.h" #include "widget.h" #include "application.h" +#include "widgetmanager.h" +#include "displaywidget.h" #include <QtGui/QGraphicsSceneEvent> @@ -50,7 +52,9 @@ SwipeModeFilter::~SwipeModeFilter() bool SwipeModeFilter::sceneEventFilter(QGraphicsItem *watched, QEvent *event) { Widget *widget = static_cast<Widget *>(watched); + const QRectF displayRect = widget->widgetManager()->display()->boundingRect(); QGraphicsSceneMouseEvent *ev = 0; + QPointF validPoint; QtSimulatorPrivate::TouchEventData touchEvent; switch (event->type()) { case QEvent::GraphicsSceneMousePress: @@ -130,17 +134,20 @@ bool SwipeModeFilter::sceneEventFilter(QGraphicsItem *watched, QEvent *event) break; case QEvent::GraphicsSceneMouseMove: ev = static_cast<QGraphicsSceneMouseEvent *>(event); + validPoint = constrainPointToRectangle(ev->pos(), displayRect); switch (mState) { case updateFirstPoint: - mValuePoints[0]->setCenter(ev->pos()); + mValuePoints[0]->setCenter(validPoint); return true; case updateSecondPoint: - mValuePoints[1]->setCenter(ev->pos()); + mValuePoints[1]->setCenter(validPoint); return true; case updateThirdPoint: { - mValuePoints[2]->setCenter(ev->pos()); - mValuePoints[1]->setCenter(mValuePoints[2]->center() - mDiff1); - mValuePoints[0]->setCenter(mValuePoints[2]->center() - mDiff2); + mValuePoints[2]->setCenter(validPoint); + validPoint = constrainPointToRectangle(ev->pos() - mDiff1, displayRect); + mValuePoints[1]->setCenter(validPoint); + validPoint = constrainPointToRectangle(ev->pos() - mDiff2, displayRect); + mValuePoints[0]->setCenter(validPoint); QtSimulatorPrivate::TouchEventData touchEvent = createTouchEventFromMouseEvent(widget, ev); QtSimulatorPrivate::RemoteMetacall<void>::call(widget->owner->socket(), QtSimulatorPrivate::NoSync, diff --git a/src/other/widget.h b/src/other/widget.h index 83d47c1..0d1204b 100644 --- a/src/other/widget.h +++ b/src/other/widget.h @@ -85,6 +85,8 @@ public: Qt::WidgetAttribute orientation() { return mOrientation; } void setOrientation(Qt::WidgetAttribute orientation) { mOrientation = orientation; } void setMouseInputMode(MultiPointTouchUi::InputMode newMode); + void setWidgetManager(WidgetManager *manager) { mManager = manager; } + WidgetManager *widgetManager() const { return mManager; } protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent* ev); diff --git a/src/other/widgetmanager.cpp b/src/other/widgetmanager.cpp index 37369f9..4c5c019 100644 --- a/src/other/widgetmanager.cpp +++ b/src/other/widgetmanager.cpp @@ -179,7 +179,7 @@ QtSimulatorPrivate::NewWindowInfo WidgetManager::create( geometry.size()); Widget *w = new Widget(geometry, mImageFormat, title, app, gWidgetIdCounter++, sharedMemoryName, parent); - w->mManager = this; + w->setWidgetManager(this); w->setWidgetVisible(false); w->offset = mOffset; w->setMouseInputMode(mCurrentMouseInputMode); |